package com.gitee.ed.arithmetic.leetcode.answer.answer_1_100.answer_1_10;

import com.gitee.ed.arithmetic.leetcode.solution.solution_1_100.solution_1_10.Solution4;

import java.util.ArrayList;
import java.util.List;

/**
 * 标准最佳方案用二分法
 *
 * @author hongda.li
 */
public class Answer4 implements Solution4 {

    @Override
    public double findMedianSortedArrays(int[] nums1, int[] nums2) {
        List<Integer> list = new ArrayList<>();

        for (int i : nums1) {
            list.add(i);
        }
        for (int i : nums2) {
            list.add(i);
        }

        list.sort(Integer::compare);

        int size = list.size();
        if (size % 2 == 0) {
            return (double) (list.get(size / 2) + list.get(size / 2 - 1)) / 2;
        } else {
            return list.get(size / 2);
        }
    }
}
